<template>
    <div class="child">
       <h2> 我是子组件</h2>
      <h3>我的玩具是:{{ toy }}</h3>
     <h3 v-if="computer">哥哥的电脑：{{ computer }}</h3>
    </div>
</template>
<script setup lang="ts">
import emitter from '@/utils/emitter';
import { onUnmounted, ref } from 'vue';
    let toy=ref('芭比娃娃')
let computer=ref('');
// 接受数据
emitter.on('sendComputer',(val:any
)=>{
    console.log('组件被调用');
computer.value=val

})
// 组件卸载事件
onUnmounted(()=>{
    emitter.off('sendComputer')   
})
</script>
<style lang="css" scoped>
    .child{
        width: 700px;
        height: 180px;
        padding:10px;
        background-color: antiquewhite;
    }
</style>